<?php

namespace app\admin\controller\scrm;

use app\common\controller\Backend;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Clist extends Backend
{
    
    /**
     * Client模型对象
     * @var \app\admin\model\scrm\Client
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\scrm\Client;
        $this->view->assign("channelList", $this->model->getChannelList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("sexList", $this->model->getSexList());
		$brandList = $this->model->getBrandList();
		$this->view->assign("brandList", $brandList);
		$labelList = $this->model->getLabellList();
		$this->view->assign("labelList", $labelList);
		$typeList = ['brand'=>(object)$brandList,'label'=>(object)$labelList];
		$this->assignconfig("typeList", $typeList);
    }
		
    /**
     * 查看
     */
    public function index($ids=null)
    {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
			
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)
				->where(['admin_id'=>$this->auth->id])
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->where($where)
				->where(['admin_id'=>$this->auth->id])
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);
		
            return json($result);
        }
		$this->assignconfig("date_arr",(object)[[date('Y-m-d'),date('Y-m-d')],[date('Y-m-d',(time()-((date('w',time())==0?7:date('w',time()))-1)*24*3600)),date('Y-m-d' , strtotime('Sunday'))],[date('Y-m-01'),date('Y-m').'-'.date('t')]]);
        return $this->view->fetch();
    }
}
